package com.test.springcloud.service;

import com.test.springcloud.entities.Dept;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * 使用feign来作为负载均衡时创建的接口；
 * <p>
 * 修改microservicecloud-api工程，
 * 根据已经有的DeptClientService接口新建一个实现了
 * FallbackFactory接口的类DeptClientServiceFallbackFactory
 *
 * @create: 2019-07-03 22:27
 **/
//@FeignClient(value = "MICROSERVICECLOUD-DEPT") //创建一个与eureka中指定名称服务映射的feign，接口方法的请求参数与服务的请求地址一致
@FeignClient(value = "MICROSERVICECLOUD-DEPT", fallbackFactory = DeptClientServiceFallbackFactory.class)
//使用降级处理时添加fallbackFactory，并指定处理类
public interface DeptClientService {

    @RequestMapping(value = "/dept/get/{id}", method = RequestMethod.GET)
    Dept get(@PathVariable("id") long id);


    @RequestMapping(value = "/dept/list", method = RequestMethod.GET)
    List<Dept> list();


    @RequestMapping(value = "/dept/add", method = RequestMethod.POST)
    boolean add(Dept dept);
}
